package com.xnyzc.lhy.order.controller.dapi.order;

import com.xnyzc.lhy.common.entity.Rv;
import com.xnyzc.lhy.common.util.TokenUtil;
import com.xnyzc.lhy.order.entity.mq.OaCOrderPersonal;
import com.xnyzc.lhy.order.entity.order.OaDOrder;
import com.xnyzc.lhy.order.entity.order.OaOrderOtherPrice;
import com.xnyzc.lhy.order.entity.param.order.*;
import com.xnyzc.lhy.order.feign.amap.IAmapService;
import com.xnyzc.lhy.order.service.order.IOaDOrderService;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;


/**
 * 司机接单控制器
 *
 * @Author: huxuekuo
 * @Date: 2019-07-22 14:11
 * @Description:
 */
@RestController
@RequestMapping("/oa/dapi/order")
public class OaDOrderController {


    @Autowired
    private IOaDOrderService service;
    @Autowired
    private IAmapService iAmapService;

    @ApiOperation(value = "添加司机订单信息", notes = "添加司机订单信息")
    @PostMapping(value = "/addDriverOrderInfo")
    public Boolean addDriverOrderInfo(
            @ApiParam(name = "oaDOrder", value = "司机接单表") @RequestBody OaDOrder oaDOrder
    ) {
        return service.addDriverOrderInfo(oaDOrder);
    }

    @ApiOperation(value = "feign滴滴取消订单", notes = "滴滴取消订单")
    @PostMapping(value = "/updateOrderPersonalStatus")
    public void updateOrderPersonalStatus(
            @ApiParam(name = "oaDOrder", value = "司机接单表") @RequestBody OrderDetailParam orderDetailParam
    ) {
        service.updateOrderPersonalStatus(orderDetailParam);
    }

    @ApiOperation(value = "feign抢单失败，修改状态", notes = "修改状态")
    @PostMapping("/singleFailureStatus")
    public Boolean singleFailureStatus(@ApiParam(name = "orderNo", value = "订单号") @RequestParam("orderNo") String orderNo) {
        return service.singleFailureStatus(orderNo);
    }

    @ApiOperation(value = "feign解除司机锁定", notes = "解除司机锁定")
    @PostMapping(value = "/driverUnlock")
    public Boolean driverUnlock(
            @ApiParam(name = "oaDOrder", value = "司机接单表") @RequestParam("driverId") String driverId
    ) {
        return service.driverUnlock(driverId);
    }

    @ApiOperation(value = "feign获取司机手机号", notes = "feign获取司机手机号")
    @PostMapping(value = "/getDriverPhone")
    public String getDriverPhone(
            @ApiParam(name = "driverId", value = "司机ID") @RequestParam("driverId") String driverId
    ) {
        return service.getDriverPhone(driverId);
    }

    @ApiOperation(value = "feign查询订单信息", notes = "feign查询订单信息")
    @PostMapping(value = "/billDetails")
    public OaCOrderPersonal billDetails(
            @ApiParam(name = "orderNo", value = "订单ID") @RequestParam("orderNo") String orderNo
    ) {
        return service.billDetails(orderNo);
    }

    @ApiOperation(value = "更新订单详细信息",notes = "更新订单详细信息")
    @PostMapping(value = "/updateOrderDetails")
    public Rv updateOrderDetails(@ApiParam(name = "OaSysOrderDetailsParam",value = "订单详细信息")
                                             @RequestBody OaSysOrderDetailsParam oaSysOrderDetailsParam){
      return service.updateOrderDetails(oaSysOrderDetailsParam);
    }
    /**
     * 乘客确认上车
     *
     * @return
     */
    @ApiOperation(value = "乘客确认上车", notes = "乘客确认上车")
    @PostMapping(value = "/notarizeGetOn")
    public Rv notarizeGetOn(
            @ApiParam(name = "orderNo", value = "订单号") @RequestBody NotarizeGetOnOrder notarizeGetOnOrder
    ) {
        return service.notarizeGetOn(notarizeGetOnOrder);
    }

    /**
     * 司机端开始行程
     *
     * @return
     */
    @ApiOperation(value = "前往预约地点", notes = "前往预约地点")
    @GetMapping(value = "/startRoute")
    public Rv startRoute(
            @ApiParam(name = "orderNo", value = "订单号")@RequestParam String orderNo) {
        return service.startRoute(String.valueOf(TokenUtil.getTokenUserId()), orderNo);
    }

    /**
     * 到达预约地点
     */
    @ApiOperation(value = "到达预约地点", notes = "到达预约地点")
    @PostMapping(value = "/arriveReservation")
    public Rv arriveReservation(
            @ApiParam(name = "orderNo", value = "订单号") @RequestBody NotarizeGetOnOrder notarizeGetOnOrder
    ) {
        return service.arriveReservation(notarizeGetOnOrder);
    }

    /**
     * 到达目的地
     *
     * @return
     */
    @ApiOperation(value = "到达目的地", notes = "到达目的地")
    @PostMapping(value = "/endTakingPassengers")
    public Rv endTakingPassengers(
            @ApiParam(name = "OrderArrivalsParam", value = "到达目的地接参类") @RequestBody OrderArrivalsParam order
    ) {
        return service.endTakingPassengers(order);
    }

    /**
     * 发起收款
     *
     * @return
     */
    @ApiOperation(value = "发起收款", notes = "发起收款")
    @PostMapping(value = "/initiatePayment")
    public Rv initiatePayment(
            @RequestBody InitiatePaymentParam paymentParam
    ) {
        return service.initiatePayment(paymentParam);
    }

    /**
     * 获取订单总金额
     *
     * @return
     */
    @ApiOperation(value = "获取订单总金额", notes = "获取订单总金额")
    @GetMapping(value = "/getInitiatePaymentInfo")
    public Rv getInitiatePaymentInfo(
            String orderNo,HttpServletRequest request
    ) {
        String appCode=request.getHeader("appCode");
        return service.getInitiatePaymentInfo(orderNo,appCode);
    }

    /**
     * 获取订单状态
     *
     * @return
     */
    @GetMapping(value = "/getDriverOrderStatus")
    public Rv getDriverOrderStatus() {
        return service.getDriverOrderStatus();
    }

    /**
     * 获取订单状态
     *
     * @return
     */
    @GetMapping(value = "/getDriverOrderDetails")
    public Rv getDriverOrderDetails(String orderNo) {
        return service.getDriverOrderDetails(orderNo);
    }

    @GetMapping("/getHistoryGps")
    @ApiOperation(value = "获取订单号轨迹信息", notes = "获取订单号轨迹信息")
    public Rv getHistoryGps(@ApiParam(name = "orderNo", value = "订单号") String orderNo) {
        return service.getHistoryGps(orderNo);
    }

    @PostMapping("/queryOrderOtherPrice")
    @ApiOperation(value = "查询订单的其他费用", notes = "查询订单的其他费用")
    public List<OaOrderOtherPrice> queryOrderOtherPrice(@RequestParam("orderNo") String orderNo) {
        return service.queryOrderOtherPrice(orderNo);
    }

    @PostMapping("/updateOrderOtherPrice")
    @ApiOperation(value = "更改其他费用", notes = "更改其他费用")
    public boolean updateOrderOtherPrice(@RequestBody List<OaOrderOtherPrice> otherPrices) {
        return service.updateOrderOtherPrice(otherPrices);
    }


    //测试上传司机位置信息
    @PostMapping("/uploadTrackFromMongo")
    @ApiOperation(value = "测试上传点位数据", notes = "测试上传点位数据")
    public boolean uploadTrackFromMongo(@RequestBody OaDOrder oaDOrder) {
        boolean result=false;
        try{
            result=iAmapService.uploadTrackFromMongo(oaDOrder);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            return result;
        }

    }

}
